﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using fqlmoney.DAL;
using fqlmoney.Common;
using fqlmoney.Model;

namespace fqlmoney.BLL
{
    public class UserInfoBLL
    {

        

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ReturnMessages AddUser(userinfo model)
        {
            ReturnMessages rm = new ReturnMessages();
            UserInfoDAL dal = new UserInfoDAL();
            try
            {
                int count = dal.AddUser(model);
                if(count>0)
                {
                    rm.code = 200;
                    rm.msg = "新增用户成功";
                }
                else
                {
                    rm.code = 701;
                    rm.msg = "新增用户失败:请联系管理员";
                }
            }
            catch(Exception e)
            {
                rm.code = 500;
                rm.msg = "服务器错误";
                LogHelper.Error(this.GetType().FullName, e.ToString());
            }
            return rm;
        }

        /// <summary>
        /// 根据qqopenid获取用户信息
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public userinfo GetModelByQQOpenid(string openid)
        {
            UserInfoDAL dal = new UserInfoDAL();
            return dal.GetModelByQQOpenid(openid);
        }

        /// <summary>
        /// 根据weiboopenid获取用户信息
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public userinfo GetModelByWeiBoOpenid(string openid)
        {
            UserInfoDAL dal = new UserInfoDAL();
            return dal.GetModelByWeiBoOpenid(openid);
        }

        /// <summary>
        /// 根据weixinopenid获取用户信息
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public userinfo GetModelByWeiXinOpenid(string openid)
        {
            UserInfoDAL dal = new UserInfoDAL();
            return dal.GetModelByWeiXinOpenid(openid);
        }

        /// <summary>
        /// 根据登录名称获取用户
        /// </summary>
        /// <param name="loginname"></param>
        /// <returns></returns>
        public userinfo GetUserInfoByLoginName(string loginname)
        {
            UserInfoDAL dal = new UserInfoDAL();
            return dal.GetUserInfoByLoginName(loginname);
        }

            /// <summary>
            /// 根据id获取用户信息
            /// </summary>
            /// <param name="uid"></param>
            /// <returns></returns>
            public userinfo GetModelByID(string uid)
        {
            UserInfoDAL dal = new UserInfoDAL();
            return dal.GetModelByID(uid);
        }

        }
}
